﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.Text;

namespace WebSite.cn
{
    public partial class news : System.Web.UI.Page
    {
        // Fields
        public string contents = "";

        public StringBuilder sbClassName = new StringBuilder();
        public StringBuilder sbContentName = new StringBuilder();


        // Methods
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                Session["URL"] = Request.Url;
                this.BindNewClass();
                this.BindContentList();
            }
        }

        private void BindNewClass()
        {
            DataTable table = SQLAccess.GreatDs("select classid, classname from DB_Newsclass where shopId=1").Tables[0];
            if ( table.Rows.Count > 0)
            {
                foreach (DataRow dr in table.Rows)
                {
                    sbClassName.AppendFormat("<li><a href=\"news.aspx?tid={0}\"><img src=\"images/arrow_2.gif\" width=\"13\" height=\"11\" align=\"absmiddle\">{1}</a></li>"
                        , dr["classid"].ToString()
                        , dr["classname"].ToString());
                }
            }
        }

        private void BindContentList()
        {

            string sSQL = "select newsid, newsname,updatetime,typeid from DB_News where 1=1 ";
               
                if(!string.IsNullOrEmpty(Request.QueryString["tid"]))
                {
                   sSQL = sSQL + " and typeid=" + Request.QueryString["tid"];
                }

                sSQL = sSQL + " order by updatetime desc,newsorder asc ";
                DataTable table = SQLAccess.GreatDs(sSQL).Tables[0];
             
                if (table.Rows.Count > 0)
                {
                   
                    foreach (DataRow dr in table.Rows)
                    {
                        sbContentName.AppendFormat(" <li><div style='float:left;'><div style='width:500px;float:left;'><a href='news_01.aspx?tid={0}&nid={1}' target='_blank'> {2}</a></div><div style='float:left;'>{3}</div></li>"
                            , dr["typeid"].ToString()
                            , dr["newsid"].ToString()
                            , dr["newsname"].ToString()
                            , dr["updatetime"].ToString());
                    }
                }
        }

    }
}